<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
        background: isHeadBack ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0)',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#EEEEEE"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text"> 福利专区 </view>
    </view>

    <scroll-view
      scroll-y="true"
      class="box"
      @scroll="scroll"
      :style="{
        height: scrollHeihgt + 'px',
      }"
      @scrolltolower="scrolltolower"
    >
      <view
        class="box_item"
        v-for="(item, index) in list"
        :key="index"
        @click="goPage(item)"
      >
        <view class="box_item_top">
          <image :src="item.file_url" mode=""></image>
          <view class="box_item_top_btn"> 火热<br />进行 </view>
        </view>
        <view class="box_item_bottom">
          <view class="box_item_bottom_title">{{ item.title }}</view>
          <view class="box_item_bottom_text">{{ item.small_title }}</view>
        </view>
      </view>
      
    </scroll-view>


    <floatingBall></floatingBall>
  </view>
</template>
    
    <script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      scrollHeihgt: 0,
      list: [
        
      ],
      isHeadBack: false,
      page:1,
      last_page:0
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - this.statusBarHeight;
      });
    });
    this.getList();
  },
  methods: {
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    goPage(item) {
      let str= ''
      if(item.title.length>10){
        str = item.title.substr(0,10) + '...'
      }
      console.log(str)
      uni.navigateTo({
        url: `/pages/integral/welfareDetail?title=${str}&id=${item.id}`,
      });
    },
    scroll(e) {
      if (e.target.scrollTop == 0) {
        this.isHeadBack = false;
      } else {
        this.isHeadBack = true;
      }
    },
    getList() {
      this.$http
        .helpFulilist({page:this.page})
        .then((res) => {
          console.log(res.data.list, "福利专区");
          this.list = this.list.concat(res.data.list.data);
          this.last_page = res.data.list.last_page
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
       this.getList()
      }
      console.log("触发");
    },
  },
};
</script>
    
    <style scoped lang="scss">
.content {
  position: fixed;
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  .slot-content {
    view {
      display: flex;
      justify-content: center;
    }
  }
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    color: #55b877;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}

.box {
  padding: 30rpx;
  box-sizing: border-box;
  height: 100%;
  .box_item {
    background: rgba(39, 39, 39, 0.5);
    border-radius: 24rpx;
    margin-bottom: 32rpx;
    .box_item_top {
      width: 100%;
      position: relative;
      image {
        width: 100%;
        height: 318rpx;
      }
      .box_item_top_btn {
        width: 92rpx;
        height: 92rpx;
        background: rgba(0, 0, 0, 0.3);
        font-size: 26rpx;
        color: #eeeeee;
        position: absolute;
        left: 0;
        top: 0;
        margin-left: 32rpx;
        margin-top: 32rpx;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    .box_item_bottom {
      padding: 32rpx;
      box-sizing: border-box;
      .box_item_bottom_title {
        font-size: 30rpx;
        color: #eeeeee;
      }
      .box_item_bottom_text {
        font-size: 24rpx;
        color: #adadad;
        margin-top: 8rpx;
      }
    }
  }
}
</style>